<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Pause</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Pause</h1>

<p>Pauses the script's <a href="../misc/Threads.htm">current thread</a>.</p>

<pre class="Syntax">#p::Pause <em>; Pressing Win+P once will pause the script. Pressing it again will unpause.</em>
Pause [, On|Off|Toggle, OperateOnUnderlyingThread?]</pre>
<h3>Parameters</h3>
<dl>

  <dt>On|Off|Toggle</dt>
  <dd><p>If blank or omitted, it defaults to Toggle. Otherwise, specify one of the following words:</p>
      <p><strong>Toggle</strong>: Pauses the <a href="../misc/Threads.htm">current thread</a> unless the thread beneath it is paused, in which case the underlying thread is unpaused.</p>
      <p><strong>On</strong>: Pauses the current thread.</p>
      <p><strong>Off</strong>: If the thread beneath the current thread is paused, it will be in an unpaused state when resumed. Otherwise, the command has no effect.<br>
      </p></dd>

  <dt>OperateOnUnderlyingThread?</dt>
  <dd><p>This parameter is ignored for <code>Pause Off</code> because that always operates on the underlying thread. For the others, it is ignored unless Pause is being turned on (including via Toggle).</p>
      <p>Specify one of the following numbers:</p>
      <p><strong>0</strong> (or omitted): The command pauses the current thread; that is, the one now running the Pause command.</p>
    <p><strong>1</strong>: The command marks the thread beneath the current thread as paused so that when it resumes, it will finish the command it was running (if any) and then enter a paused state. If there is no thread beneath the current thread, the script itself is paused, which prevents <a href="SetTimer.htm">timers</a> from running (this effect is the same as having used the menu item &quot;Pause Script&quot; while the script has no threads).</p>
    <p>Note: <a href="../Variables.htm#IsPaused">A_IsPaused</a> contains the pause state of the underlying thread.</p></dd>

</dl>

<h3>Remarks</h3>
<p>Unlike <a href="Suspend.htm">Suspend</a> -- which disables <a href="../Hotkeys.htm">hotkeys</a> and <a href="../Hotstrings.htm">hotstrings</a> -- turning on pause will freeze the <a href="../misc/Threads.htm"> current thread</a>. As a side-effect, any interrupted threads beneath it will lie dormant.</p>
<p>Whenever any thread is paused, <a href="SetTimer.htm">timers</a> will not run. By contrast, explicitly launched threads such as <a href="../Hotkeys.htm">hotkeys</a> and <a href="Menu.htm">menu items</a> can still be launched; but when their <a href="../misc/Threads.htm">threads</a> finish, the underlying thread will still be paused. In other words, each thread can be paused independently of the others.</p>
<p>The color of the tray icon changes from green to red whenever the script's <a href="../misc/Threads.htm">current thread</a> is in a paused state. This color change can be avoided by freezing the icon, which is achieved by specifying 1 for the last parameter of the Menu command. For example:</p>
  <pre><a href="Menu.htm">Menu</a>, Tray, Icon, C:\My Icon.ico, , 1</pre>
<p>To disable <a href="SetTimer.htm">timers</a> without pausing the script, use <a href="Thread.htm">Thread, NoTimers</a>.</p>
<p>The Pause command is similar in function to the built-in menu item &quot;Pause Script&quot;.</p>
<p>A script is always halted (though not officially paused) while it is displaying any kind of <a href="Menu.htm">menu</a> (tray menu, menu bar, GUI context menu, etc.)</p>
<h3>Related</h3>
<p><a href="Suspend.htm">Suspend</a>, <a href="Menu.htm">Menu</a>, <a href="ExitApp.htm">ExitApp</a>, <a href="../misc/Threads.htm">Threads</a>, <a href="SetTimer.htm">SetTimer</a></p>
<h3>Examples</h3>
<pre class="NoIndent">Pause::Pause  <em>; Assign the toggle-pause function to the &quot;pause&quot; key...</em>
#p::Pause  <em>; ... or assign it to Win+p or some other hotkey.</em></pre>

<pre id="PostMessage" class="NoIndent"><em>; Send a Pause command to another script.</em>
<a href="DetectHiddenWindows.htm">DetectHiddenWindows</a>, On
WM_COMMAND := 0x111
ID_FILE_PAUSE := 65403
<a href="PostMessage.htm">PostMessage</a>, WM_COMMAND, ID_FILE_PAUSE,,, C:\YourScript.ahk ahk_class AutoHotkey</pre>

</body>
</html>
